Java™ applications and frameworks may deal directly with native data, memory that is allocated outside a JAVA heap. (JAVA and all JAVA-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates.) Examples include operating system data structures, transmitted data, data streamed from a file, and data shared with another application that is not a JAVA application.
A packed object data model offers advantages relative to conventional JAVA programming, including reducing overhead associated with data marshalling, reducing overall memory footprint, and increasing object locality. In the packed object data model fields of primitive data type generally occupy a smallest amount of space necessary. Non-primitive data type fields can use packed types, in which the data is embedded rather than existing in a separate object. Elements of a packed array contain data rather than references to other objects. Packed objects can also contain data that is allocated outside of the JAVA heap.
More particularly, in a packed object data model fields of a primitive data type (for example, “byte” or “int”) occupy a minimum amount of necessary space. Thus, “byte” or “boolean” field types generally occupy a single byte; “short” or “char” types occupy two bytes; “int” or “float” types occupy four bytes; and “long” or “double” types occupy 8 bytes. This is in contrast to a standard JAVA object where all primitive data type fields are stored in either 32-bit (for example, “byte, short, int, float, char” and “boolean” data types) or 64-bit format (for example, “long” and “double” data types), which is relatively more wasteful of resources, especially when there are multiple fields of a small primitive data type.
Packed classes may also contain fields of non-primitive data types. For normal object and array types, these fields behave exactly like any other non-primitive data type field in the JAVA language, and wherein the field contains a reference (or a pointer) to either a field value or “null” value. A packed object with one or more fields of this type is sometimes referred to as a “mixed packed object,” or “mixed,” and is subject to some additional restrictions relative to a standard JAVA data model.
Fields of packed types also behave differently relative to a standard JAVA data model. For example, an instance field of a packed type in a packed class may not result in a reference to another object, but instead to data fields of the embedded type. A field of this type is sometimes referred to as a “nested field,” or “nested.”